package com.gonsin.gview.common.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gonsin.gview.common.bean.UserMenuBean;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMenuMapper extends BaseMapper<UserMenuBean> {


    @Results(id = "UserMenuBean",
        value = {
            @Result(property = "menuKey", column = "menu_key"),
            @Result(property = "edificeKey", column = "edifice_key"),
            @Result(property = "show", column = "gs_show"),
        }
    )
    @Select("select " +
            "um.* " +
            "from gs_user_user_menu as um " +
            "where um.edifice_key = #{edificeKey} " +
            "order by um.sort asc ")
    List<UserMenuBean> selectByEdificeKey(@Param("edificeKey") String edificeKey);


    @Select("<script>" +
            "select " +
            "um.* " +
            "from gs_user_user_menu as um " +
            "where um.edifice_key = #{edificeKey} " +
            "and um.name in " +
            " <foreach item=\"item\" index=\"index\" collection=\"permissions\" open=\"(\" separator=\",\" close=\")\"> " +
            "       #{item} " +
            "   </foreach> " +
            "order by um.sort asc " +
            "</script>")
    List<UserMenuBean> selectUserMenu(@Param("edificeKey") String edificeKey, List<String> permissions);

    @ResultMap("UserMenuBean")
    @Select("select * from gs_user_user_menu where menu_key = #{menuKey}")
    UserMenuBean getMenu(String menuKey);
}